import time
from selenium import webdriver

def write_local_file(filename,text):
    with open(filename,"w",encoding="utf-8") as file:
        file.write(text)
        file.close()

def read_local_file(filename):
    with open(filename,"r",encoding="utf-8") as file:
        file.read(filename)
        file.close()

def fetch_website(url):
    driver = webdriver.Firefox()
    driver.get(url)
    return driver

def JD_Login(driver):
    # driver.switch_to_frame("login_frame")
    driver.find_element_by_xpath('//div[@class="login-form"]/div[3]').click()
    time.sleep(1)

    driver.find_element_by_id('loginname').clear()
    driver.find_element_by_id('loginname').send_keys("18729583659")
    driver.find_element_by_id('nloginpwd').clear()
    driver.find_element_by_id('nloginpwd').send_keys("zenglong19940519")
    driver.find_element_by_id('loginsubmit').click()
    return driver

def driver_wait(driver):
    time.sleep(10)
    driver.quit()


if __name__ == "__main__":
    url = "https://passport.jd.com/new/login.aspx?ReturnUrl=https%3A%2F%2Fwww.jd.com%2F"
    driver = fetch_website(url)
    driver_now = JD_Login(driver)
    driver_wait(driver_now)